package com.lvbaoins.creditapp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lvbaoins.creditapp.mapper.InsUserMapper;
import com.lvbaoins.creditapp.model.InsUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


/**
 * <p>
 * system 服务
 * </p>
 *
 * @author gjb
 * @Date 2020-03-30 18:32:14
 */
@Service
public class InsUserService extends ServiceImpl<InsUserMapper, InsUser> {

    /**
     * 分页查询
     *
     * @param pageIndex
     * @param limit
     * @param insUser
     * @return
     */
    public IPage<InsUser> pageList(Integer pageIndex, Integer limit, InsUser insUser) {
        Page page = new Page<InsUser>(pageIndex, limit);
        QueryWrapper<InsUser> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNoneBlank(insUser.getAccount())){
            queryWrapper.likeRight("account", insUser.getAccount());
        }
        if(StringUtils.isNoneBlank(insUser.getName())){
            queryWrapper.like("name", insUser.getName());
        }
        if(StringUtils.isNoneBlank(insUser.getTel())){
            queryWrapper.likeRight("tel", insUser.getTel());
        }
        queryWrapper.orderByDesc("id");
        return this.page(page, queryWrapper);
    }


    /**
     * 根据账户获取用户信息
     * @param account
     */
    public InsUser getUserByAccount(String account){

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("account", account);
        return this.getOne(queryWrapper);
    }


    public InsUser getUserByOpenId(String openId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("open_id", openId);
        return this.getOne(queryWrapper);
    }


}
